package com.liam.socket.udp;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetSocketAddress;

public class Server {

    public static void main(String[] args) throws Exception {
        // 创建客户端
        DatagramSocket socket = new DatagramSocket(new InetSocketAddress("127.0.0.1",61610));


        // 创建集装箱
        byte[] bytes = new byte[1024];
        DatagramPacket packet = new DatagramPacket(bytes,bytes.length);
        // 接收
        socket.receive(packet);
        // 打印
        System.out.println(new String(packet.getData(),0,packet.getLength()));


        byte [] bs = "服务端收到了".getBytes();
        // 创建集装箱
        DatagramPacket res = new DatagramPacket(bs,bs.length,packet.getAddress(),packet.getPort());
        // 发送数据
        socket.send(res);



        // 关闭资源
        socket.close();


    }
}
